/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sapra.echo;

import echopointng.BorderEx;
import echopointng.ContainerEx;
import echopointng.DateField;
import echopointng.ExtentEx;
import echopointng.Menu;
import echopointng.MenuItem;
import echopointng.layout.DisplayLayoutData;
import java.text.SimpleDateFormat;
import nextapp.echo2.app.Alignment;
import nextapp.echo2.app.Border;
import nextapp.echo2.app.Button;
import nextapp.echo2.app.CheckBox;
import nextapp.echo2.app.Color;
import nextapp.echo2.app.Column;
import nextapp.echo2.app.Component;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.FillImage;
import nextapp.echo2.app.FillImageBorder;
import nextapp.echo2.app.Font;
import nextapp.echo2.app.Insets;
import nextapp.echo2.app.Label;
import nextapp.echo2.app.ListBox;
import nextapp.echo2.app.PasswordField;
import nextapp.echo2.app.ResourceImageReference;
import nextapp.echo2.app.Row;
import nextapp.echo2.app.SelectField;
import nextapp.echo2.app.SplitPane;
import nextapp.echo2.app.Table;
import nextapp.echo2.app.TextField;
import nextapp.echo2.app.WindowPane;
import nextapp.echo2.app.event.ActionListener;
import nextapp.echo2.extras.app.TabPane;

/**
 *
 * @author ppratsc
 */
public class Helpers {
static String DIR_IMAGEN="org/sapra/echo/image/";

    public static SplitPane SplitPanel(int orient,Extent ext,boolean resize,Component parent){
        SplitPane resp = new nextapp.echo2.app.SplitPane();
        resp.setOrientation(orient);
        resp.setResizable(resize);
        resp.setSeparatorPosition(ext);
        resp.setSeparatorColor(Color.BLACK);
        parent.add(resp);

        return resp;
    }
    public static Label Label(String text,Color color,Component parent){
        Label resp = new Label(text);
        if(color != null) resp.setForeground(color);
        resp.setFont(new Font(new Font.Typeface("arial"),1,new Extent(13)));
        parent.add(resp);
        return resp;
    }

    public static Row Row(String style,Extent ext,Component parent){
        Row resp = new nextapp.echo2.app.Row();
        resp.setStyleName(style);
        resp.setCellSpacing(ext);
        resp.setAlignment(new Alignment(100,200));
        parent.add(resp);
        return resp;
    }
    public static Column Column(String style,Extent ext,Component parent){
        Column resp = new nextapp.echo2.app.Column();
        resp.setStyleName(style);
        resp.setCellSpacing(ext);
        parent.add(resp);
        return resp;
    }
    public static MenuItem menuItem(String text,ActionListener action){
        MenuItem resp=new MenuItem(text);
        resp.setHeight(new Extent(20));
        //resp.setStyleName("Default");
        resp.setTextAlignment(new nextapp.echo2.app.Alignment(Alignment.CENTER,Alignment.CENTER));
        //resp.setTextPosition(new nextapp.echo2.app.Alignment(Alignment.CENTER,Alignment.BOTTOM));
        resp.setFont(new Font(Font.ARIAL, 1, new Extent(12)));
        resp.setWidth(new Extent(110));
        //resp.setHeight(new Extent(15));
        if(action != null)resp.addActionListener(action);
        return resp;
    }
    public static Button Button(String text,Component parent,ActionListener action){
        Button resp = new nextapp.echo2.app.Button(text);
        resp.setStyleName("Default");
        resp.setTextAlignment(new nextapp.echo2.app.Alignment(Alignment.CENTER,Alignment.CENTER));
        resp.setTextPosition(new nextapp.echo2.app.Alignment(Alignment.CENTER,Alignment.CENTER));
        resp.setBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN + "fondo_titulo2.png")));
        if(action != null)resp.addActionListener(action);
        parent.add(resp);

        return resp;
    }
    public static Button botonMenu(String text,ActionListener action){
         Button resp = new nextapp.echo2.app.Button(text);
        resp.setStyleName("Default");
        resp.setTextAlignment(new nextapp.echo2.app.Alignment(Alignment.CENTER,Alignment.CENTER));
        resp.setTextPosition(new nextapp.echo2.app.Alignment(Alignment.CENTER,Alignment.BOTTOM));
        resp.setBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN + "boton4.png")));
        if(action != null)resp.addActionListener(action);
        return resp;
    }
    public static TextField Text(String text, Component parent) {
        TextField resp = new TextField();
        resp.setText(text);
        parent.add(resp);
        return resp;
    }
        public static PasswordField Password(String text, Component parent) {
        PasswordField resp = new PasswordField();
        resp.setText(text);
        parent.add(resp);
        return resp;
    }

    public static SelectField SelectField(Component parent,ActionListener action) {
        SelectField resp = new SelectField();
        if(action != null)resp.addActionListener(action);
        parent.add(resp);
        return resp;
    }

    public static ListBox ListBox(Component parent, ActionListener action) {
        ListBox resp = new ListBox();
        resp.addActionListener(action);
        parent.add(resp);
        return resp;
    }

    public static CheckBox CheckBox(String txt, Component parent) {
        CheckBox resp = new CheckBox(txt);
        resp.setBorder(new Border(new Extent(3),Color.WHITE,5));
        resp.setHeight(new Extent(20));
        parent.add(resp);
        return resp;
    }

    public static DateField DateField(Component parent){
        DateField resp = new DateField();
        resp.setUpdateFromTextField(true);
        resp.setDateFormat(new SimpleDateFormat("dd-MM-yyyy"));
        resp.getDateChooser().setYearSelectable(true);
        resp.getDateChooser().setNavigationArrowsVisible(true);
        resp.getDateChooser().setYearRange(50);
        parent.add(resp);
        return resp;
    }

    public static String quitarAcento(String s){
        //String prueba="ÑHernández-Mo123rán J12osué Wilfrido";
 		//áéíóú
                s=s.toLowerCase().trim();
 		s=s.replace('Ñ', 'N').replace('á', 'A').replace('é', 'E').replace('í', 'I');
 		s=s.replace('ó','O').replace('ú', 'U').replace('ñ', 'N');
 		s=s.toUpperCase();
 		s=s.trim();

 		String cad="";
 		for(int i=0;i<s.length();i++){
 			char m=s.charAt(i);
                        if(Character.isLetter(m)||Character.isDigit(m))
 					cad=cad+m;
                        else
                            cad=cad+" ";
 		}
 		s=cad;


		return s;
    }

    public static Button Button2(String text,ActionListener action){
        Button resp = new nextapp.echo2.app.Button(text);
        resp.setStyleName("Default");
        resp.setTextAlignment(new nextapp.echo2.app.Alignment(Alignment.CENTER,Alignment.CENTER));
        resp.setTextPosition(new nextapp.echo2.app.Alignment(Alignment.CENTER,Alignment.BOTTOM));
        resp.setBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN + "fondo_titulo2.png")));
        resp.setHeight(new Extent(20));
        resp.setWidth(new Extent(90));
        if(action != null)resp.addActionListener(action);
        return resp;
    }

    public static Row rowTextField(String title,int espacio,TextField tFld,int Insts){
            Row r=new Row();
            Label l=new Label(title);
            l.setFont(new nextapp.echo2.app.Font(Font.ARIAL, 1, new Extent(13)));
            tFld.setFont(new nextapp.echo2.app.Font(Font.ARIAL, 1, new Extent(13)));

            r.setInsets(new Insets(Insts));
            r.setCellSpacing(new Extent(espacio));
            r.add(l);
            r.add(tFld);

            return r;
        }

    public static WindowPane Window(String title ){
        WindowPane resp=new WindowPane();
        resp.setTitle(title);
        resp.setTitleBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN+"fondo_titulo2.png")));
        resp.setBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN+"fondo.jpg")));
        resp.setTitleFont(new Font(Font.HELVETICA,1, new Extent(14)));
        resp.setClosable(true);
        resp.setMovable(false);
        resp.setResizable(false);
        return resp;
    }

    public static Table Tabla(){
        Table resp=new Table();
         resp.setStyleName("Default");
         resp.setHeaderVisible(true);
         //resp.setBorder(BorderEx.DEFAULT);
         resp.setBackground(Color.WHITE);
         resp.setSelectionEnabled(true);
         resp.setRolloverEnabled(true);
         resp.setRolloverForeground(Color.WHITE);
         resp.setSelectionBackground(Color.YELLOW);
         resp.setRolloverBackground(new Color(255,140,0));

         //resp.setRolloverForeground(Color.RED);new Color(	255,69,0)
         //resp.setSelectionForeground(Color.WHITE);
         resp.setBorder(new Border(5,Color.BLUE, 1));
        return resp;
    }

    public static TabPane TabPanel(){
        TabPane resp=new TabPane();
        resp.setTabActiveBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN+"fondo_titulo2.png")));
        resp.setTabInactiveBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN+"boton4.png")));
        resp.setTabActiveForeground(Color.YELLOW);
        resp.setTabInactiveForeground(Color.WHITE);
        resp.setFont(new Font(Font.VERDANA, 1, new Extent(14)));
        resp.setBackground(new Color(180,190,255));
        resp.setBorderType(0);
        resp.setTabActiveBorder(new Border(0,Color.BLACK,0));
        resp.setTabInactiveBorder(new Border(0,Color.BLACK,0));
        return resp;
    }

    //este metodo es opcional
    public static Menu estiloMenu(String nombre){
        Menu resp=new Menu(nombre);
        //resp.setWidth(new Extent(120));
        resp.setBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN+"fondo_titulo2.png")));
        resp.setForeground(Color.WHITE);
        resp.setBorder(new Border(new Extent(2),Color.WHITE,5));
        resp.setRolloverForeground(Color.BLACK);
        resp.setRolloverBackground(new Color(235,235,0));
        resp.setFont(new Font(Font.ARIAL, 1, new Extent(14)));
        //resp.setBorder(new Border(3,Color.BLACK, 3));
        return resp;
    }
    public static SplitPane SplitPaneHelper(int orient,Extent ext,boolean resize){
        SplitPane resp = new nextapp.echo2.app.SplitPane();
        resp.setOrientation(orient);
        resp.setResizable(resize);
        resp.setSeparatorPosition(ext);
        resp.setSeparatorColor(Color.BLACK);

        return resp;
    }

    public static Row rowLabel(String title,Color color){
            Row r=new Row();
            Label l=new Label(title);
            l.setFont(new nextapp.echo2.app.Font(Font.ARIAL, 1, new Extent(12)));
            l.setForeground(color);
            r.add(l);
            //r.setBorder(new Border(1, Color.BLACK, 1));r.setInsets(new Insets(10));
            return r;
    }
    public static ContainerEx contenedor(){
         ContainerEx contenedor=new ContainerEx();
         contenedor.setWidth(new ExtentEx("100%"));
         contenedor.setHeight(new ExtentEx("100%"));
         //contenedor.setBorder(new BorderEx());

         return contenedor;
    }

    public static DisplayLayoutData displaylayout(){
         DisplayLayoutData dsd=new DisplayLayoutData();
         dsd.setWidth(new ExtentEx("100%"));
         dsd.setHeight(new ExtentEx("100%"));
         return dsd;
    }

     public static Button botonesMenu(String title,int height,int width,Color color,Color colorFont){
        Button but=new Button();
        but.setText(title);
        but.setHeight(new Extent(height));
        but.setWidth(new Extent(width));
        but.setBackground(color);
        but.setForeground(colorFont);
        but.setBorder(new nextapp.echo2.app.Border(new Extent(1,Extent.PX), Color.BLACK, 1));
        but.setAlignment(Alignment.ALIGN_CENTER);
        but.setTextAlignment(Alignment.ALIGN_CENTER);
        return but;
    }

     public static Table compTable(){
        Table t=new Table();
            t.setVisible(true);
            t.setVisible(true);
            t.setWidth(new Extent(1000,Extent.PX));
            t.setInsets(new nextapp.echo2.app.Insets(5));
            t.setSelectionEnabled(true);
            t.setSelectionFont(new Font(Font.ARIAL,1, new Extent(8)));
            t.setSelectionBackground(new Color(220,20,60));
            t.setSelectionForeground(Color.WHITE);
            t.setRolloverEnabled(true);
            t.setRolloverBackground(new Color(255,128,128));
            t.setRolloverForeground(Color.WHITE);
        return t;
    }
     public static WindowPane Ventana(Color color,Extent PosX,Extent PosY,Extent Width,Extent Height,Boolean cierre,Boolean resize,Extent medidaTitle){
            WindowPane wp=new WindowPane();
            wp.setBackground(color);
            wp.setPositionX(PosX);
            wp.setPositionY(PosY);
            wp.setWidth(Width);
            wp.setHeight(Height);
            wp.setClosable(cierre);
            wp.setResizable(resize);
            wp.setTitleHeight(medidaTitle);
            return wp;
    }

     public static TextField textLabels(int largo,int longitud,boolean habilitado){
            TextField txt=new TextField();
            txt.setFont(new nextapp.echo2.app.Font(Font.ARIAL, 1, new Extent(12)));
            txt.setWidth(new Extent(largo,Extent.PX));
            txt.setMaximumLength(longitud);
            txt.setEnabled(habilitado);
            txt.setAlignment(Alignment.ALIGN_LEFT);
            //txt.setBorder(new nextapp.echo2.app.Border(2, Color.BLACK, 2));
            txt.setHeight(new Extent(15));
            return txt;
        }
}


